﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Lost_and_Found.Models.DB;

namespace Lost_and_Found.Models.ObjectManager
{
    public class LAFManager
    {
        LAFEntities db = new LAFEntities();
        public void AddInfoOfLostTopic(FormCollection formCollection,Topic topic,string userName)
        {
            
            //Label "Topic"
            topic.Title = formCollection["Title"];
            string date = formCollection["Date"];
            DateTimeFormatInfo dt = new DateTimeFormatInfo();
            dt.ShortDatePattern = "yyyy-mm-dd";
            dt.DateSeparator = "-";
            topic.Date = Convert.ToDateTime(date, dt);
            topic.DatePost = DateTime.Now;
            topic.Location = formCollection["hiddenTagLocation"];
            topic.Type = "Lost";
            topic.Description = formCollection["Description"];
            User user = db.Users.Single(a => a.Username == userName);
            topic.UserID = user.Id;
            db.Topics.Add(topic);
            db.SaveChanges();
        }

        public void AddInfoOfGetTopic(FormCollection formCollection, Topic topic, string userName)
        {

            //Label "Topic"
            topic.Title = formCollection["Title"];
            string date = formCollection["Date"];
            DateTimeFormatInfo dt = new DateTimeFormatInfo();
            dt.ShortDatePattern = "yyyy-mm-dd";
            dt.DateSeparator = "-";
            topic.Date = Convert.ToDateTime(date, dt);
            topic.DatePost = DateTime.Now;
            topic.Location = formCollection["hiddenTagLocation"];
            topic.Type = "Get";
            topic.Description = formCollection["Description"];
            User user = db.Users.Single(a => a.Username == userName);
            topic.UserID = user.Id;
            db.Topics.Add(topic);
            db.SaveChanges();
        }

        
    }
}